<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <style>
        body {
            background-color: #f8f9fa;
        }

        .pet-details {
            margin-top: 20px;
            background-color: #ffffff;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }

        .pet-details img {
            max-width: 100%;
            height: auto;
            border-radius: 8px;
        }

        .pet-details h2 {
            color: #495057;
        }

        .pet-details p {
            color: #6c757d;
        }

        .pet-details .btn-adopt {
            background-color: #28a745;
            color: #fff;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .pet-details .btn-adopt:disabled {
            background-color: #6c757d;
            cursor: not-allowed;
        }

        .navbar {
            background-color: #343a40;
        }

        .navbar-dark .navbar-brand,
        .navbar-dark .navbar-toggler-icon {
            color: #ffffff;
        }

        .navbar-dark .navbar-nav .nav-link {
            color: #ffffff;
        }

        .navbar-dark .navbar-toggler {
            border-color: #ffffff;
        }

    </style>
    <title>宠物详情</title>
</head>
<body>

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <a class="navbar-brand" href="/index.html">首页</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
            aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item">
                <a class="nav-link" href="/adopt.html">我的领养</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="/person.html">个人信息</a>
            </li>
        </ul>
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="/logout">退出</a>
            </li>
        </ul>
    </div>
</nav>

<div class="container pet-details" id="petDetailsContainer">
</div>

<script src="/js/jquery.min.js"></script>
<script>
    $.ajax({
        url: '/detail?id=' + getParameterByName("id"),
        method: 'GET',
        success: function (data) {
            var petDetailsHtml = '<div class="row">' +
                '<div class="col-md-6">' +
                '<img src="' + data.image + '" class="img-fluid" alt="宠物图片">' +
                '</div>' +
                '<div class="col-md-6">' +
                '<h2>' + data.name + '</h2>' +
                '<p><strong>类型:</strong> ' + data.type + '</p>' +
                '<p><strong>性别:</strong> ' + data.gender + '</p>' +
                '<p><strong>状态:</strong> ' + data.status + '</p>' +
                '<p><strong>简介:</strong> ' + data.intro + '</p>' +
                '<button class="btn btn-adopt" ' + (data.status === "已领养" ? 'disabled' : '') + ' onclick="adopt('+data.id+')">申请领养</button>' +
                '</div>' +
                '</div>';
            $('#petDetailsContainer').append(petDetailsHtml);
        },
        error: function (error) {
            console.error('出错:', error);
        }
    });

    function getParameterByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    }

    function adopt(id) {
        window.location.href = "/apply/adopt?petId=" + id
        alert("申请成功,请等待管理员审核！")
        location.reload()
    }


</script>

</body>
</html>
